package com.example.springtransactional.service;

import com.example.springtransactional.dao.InsertDataDao;
import com.example.springtransactional.domain.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @auther:lgb
 * @Date: 2021/4/24
 */
@Service
public class TestAService {
    @Resource
    InsertDataDao insertDataDao;

    @Transactional(rollbackFor = {Exception.class}, timeout = 1, propagation = Propagation.NESTED)
    public void methodA() {
        insertDataDao.insertData(new User(2, "MethodA", 10));
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        insertDataDao.insertData(new User(2, "MethodA", 10));


    }
}
